package com.tz.actions;

import com.opensymphony.xwork2.ActionSupport;
import com.tz.entity.Category;
import com.tz.entity.Product;
import com.tz.service.ProductService;
import com.tz.service.ProductServiceImpl;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Tinyang on 2016/7/24.
 */
@Namespace("/product")
public class ProductDetailsAction extends ActionSupport {

    private long product_id;
    private Product product;
    private List<Category> categoryList;
    @Autowired
    private ProductService productService;


    //ProductBysService1 productBysService= MyAcUtil.getAc().getBean(ProductBysService1.class);
    //ProductBysService1 categoryService= MyAcUtil.getAc().getBean(ProductBysService1.class);
    public ProductDetailsAction() {
        // Map<String, Object> application = ActionContext.getContext().getApplication();
        //ApplicationContext ac = (ApplicationContext) application.get("ac");
        //System.out.println("我们来看一下ac内存地址:" + ac);
        //this.productBysService = ac.getBean(ProductBysService1.class);
        //this.categoryService = ac.getBean(ProductBysService1.class);
    }

    @Action(value = "details", results = {
            @Result(location = "/product_details.jsp")
    })
    public String selectProduct() {
        product = productService.getProduct(product_id);
        categoryList = productService.getAllCategories();

        return SUCCESS;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public List<Category> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Category> categoryList) {
        this.categoryList = categoryList;
    }


    public long getProduct_id() {
        return product_id;
    }

    public void setProduct_id(long product_id) {
        this.product_id = product_id;
    }
}
